package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.UrgentHandleEquipment;
import com.ruoyi.system.mapper.UrgentHandleEquipmentMapper;
import com.ruoyi.system.service.UrgentHandleEquipmentService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 紧急处理设施(UrgentHandleEquipment)表服务实现类
 *
 * @author makejava
 * @since 2022-11-16 14:50:15
 */
@Service("urgentHandleEquipmentService")
public class UrgentHandleEquipmentServiceImpl implements UrgentHandleEquipmentService {
    @Resource
    private UrgentHandleEquipmentMapper urgentHandleEquipmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public UrgentHandleEquipment queryById(Integer id) {
        return this.urgentHandleEquipmentDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param urgentHandleEquipment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<UrgentHandleEquipment> queryByPage(UrgentHandleEquipment urgentHandleEquipment, PageRequest pageRequest) {
        long total = this.urgentHandleEquipmentDao.count(urgentHandleEquipment);
        return new PageImpl<>(this.urgentHandleEquipmentDao.queryAllByLimit(urgentHandleEquipment, pageRequest), pageRequest, total);
    }

    @Override
    public List<UrgentHandleEquipment> selectList(UrgentHandleEquipment urgentHandleEquipment) {
        return urgentHandleEquipmentDao.queryAll(urgentHandleEquipment);
    }

    /**
     * 新增数据
     *
     * @param urgentHandleEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public UrgentHandleEquipment insert(UrgentHandleEquipment urgentHandleEquipment) {
        this.urgentHandleEquipmentDao.insert(urgentHandleEquipment);
        return urgentHandleEquipment;
    }

    /**
     * 修改数据
     *
     * @param urgentHandleEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public UrgentHandleEquipment update(UrgentHandleEquipment urgentHandleEquipment) {
        this.urgentHandleEquipmentDao.update(urgentHandleEquipment);
        return this.queryById(urgentHandleEquipment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.urgentHandleEquipmentDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<UrgentHandleEquipment> urgentHandleEquipments, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(urgentHandleEquipments) || urgentHandleEquipments.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        urgentHandleEquipmentDao.insertBatch(urgentHandleEquipments);
        return "成功";
    }
}
